package com.panasonic.web.controller.cms;

import com.panasonic.common.annotation.Log;
import com.panasonic.common.core.controller.BaseController;
import com.panasonic.common.core.domain.AjaxResult;
import com.panasonic.common.core.page.TableDataInfo;
import com.panasonic.common.enums.BusinessType;
import com.panasonic.web.domain.cms.CmsPermission;
import com.panasonic.web.service.ICmsPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限Controller
 * 
 * @author lwf
 * @date 2021-11-13
 */
@RestController
@RequestMapping("/cms/permission")
@Api(value = "CmsPermission", tags = "权限")
public class CmsPermissionController extends BaseController
{
    @Autowired
    private ICmsPermissionService cmsPermissionService;

    /**
     * 查询权限列表
     */
    @ApiOperation(value = "查询")
    @GetMapping("/list")
    public TableDataInfo list(CmsPermission cmsPermission)
    {
        startPage();
        List<CmsPermission> list = cmsPermissionService.selectCmsPermissionList(cmsPermission);
        return getDataTable(list);
    }


    /**
     * 获取权限详细信息
     */
    @ApiOperation(value = "获取权限详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsPermissionService.selectCmsPermissionById(id));
    }

    /**
     * 新增权限
     */
    @ApiOperation(value = "新增权限")
    @Log(title = "权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsPermission cmsPermission)
    {
        return toAjax(cmsPermissionService.insertCmsPermission(cmsPermission));
    }

    /**
     * 修改权限
     */
    @ApiOperation(value = "修改权限")
    @Log(title = "权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsPermission cmsPermission)
    {
        return toAjax(cmsPermissionService.updateCmsPermission(cmsPermission));
    }

    /**
     * 删除权限
     */
    @ApiOperation(value = "删除权限")
    @Log(title = "权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsPermissionService.deleteCmsPermissionByIds(ids));
    }
}
